package com.itluma.isWOak.controller;


import com.github.pagehelper.PageInfo;
import com.itluma.isWOak.pojo.*;

import com.itluma.isWOak.service.BillService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;


@Controller
public class BillController {

    @Autowired
    private BillService billService;


    @PostMapping("/bill/bill_list1")
    public String list1(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "1") Integer limit, Model model,HttpServletRequest req) {

        String username = req.getParameter("username");
         System.out.println(username);

        String idcard = req.getParameter("idcard");
        System.out.println(idcard);

        String account = req.getParameter("account");
        System.out.println(account);

        String month = req.getParameter("month");
        System.out.println(month);
        String year = req.getParameter("year");
        System.out.println(year);



        return "/bill/bill_list";
    }






    @RequestMapping("/bill/bill_list")
    public String list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "1") Integer limit, Model model) {
        PageInfo<NewAccount> pageInfo = billService.page1(page, limit);
        System.out.println(pageInfo.getList());
        model.addAttribute("pageInfo", pageInfo);
        return "/bill/bill_list";
    }


    @RequestMapping("/bill/bill_item")
    public String item(HttpServletRequest request, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "1") Integer limit, Model model, NewAccount newAccount, NewService newService) {


        PageInfo<NewService> pageInfo = billService.page2(page, limit,  newService.getBillId());

        if(pageInfo.getPages()!=0){
             System.out.println("不为空");
        System.out.println(pageInfo.getList());
        model.addAttribute("pageInfo", pageInfo);
        model.addAttribute("newAccount", newAccount);
        model.addAttribute("newService", newService);
        return "/bill/bill_item";
        } else {
            System.out.println("空的");
            PageInfo<NewAccount> pageInfos = billService.page1(page, limit);
            System.out.println(pageInfos.getList());
            model.addAttribute("pageInfo", pageInfos);
            return "/bill/bill_list";

        }
    }


    @RequestMapping("/bill/bill_service_detail")
    public String service_detail(HttpServletRequest request, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "1") Integer limit, Model model, NewService newService,NewAccount newAccount) {


        PageInfo<NewService> pageInfo = billService.page3(page, limit);
        System.out.println(pageInfo.getList());
        model.addAttribute("newService", newService);
        model.addAttribute("newAccount", newAccount);
        model.addAttribute("pageInfo", pageInfo);
        return "bill/bill_service_detail";
    }

}
